package com.design03_behavioral.pattern16_responsibilityChains.example03;

import com.design03_behavioral.pattern16_responsibilityChains.example02.AuthInfo;
import com.design03_behavioral.pattern16_responsibilityChains.example02.AuthService;

import java.text.ParseException;
import java.util.Date;

/**
 * @ClassName 二级审批人
 * @Description TODO
 * @Author zhangjunhao
 * @DATE 2023/9/9 1:03
 */
public class Level2AuthLink extends AuthLink {

    private Date beginDate = f.parse("2020-11-11 00:00:00");
    private Date endDate = f.parse("2020-11-31 23:59:59");

    public Level2AuthLink(String levelUserId, String levelUserName) throws ParseException {
        super(levelUserId, levelUserName);
    }

    @Override
    public AuthInfo doAuth(String uId, String orderId, Date authDate) {
        Date date = AuthService.queryAuthInfo(levelUserId, orderId);
        if (null == date) {
            return new AuthInfo("0001", "单号：", orderId, " 状态：待二级审批负责人 ", levelUserName);
        }


        AuthLink next = super.getNext();
        if (null == next) {
            return new AuthInfo("0000", "单号：", orderId, " 状态：二级审批完成", " 时间：", f.format(date), " 审批人：", levelUserName);
        }

        //如果不在这个时间点,只到达这一步
        if (authDate.before(beginDate) || authDate.after(endDate) ) {
            return new AuthInfo("0000", "单号：", orderId, " 状态：二级审批完成", " 时间：", f.format(date), " 审批人：", levelUserName);
        }


        return next.doAuth(uId, orderId, authDate);

    }
}
